package cn.com.linht.jsontosql.entity;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * 原始表sql
 *
 * @author linht
 */
public class OriginalTableVO {

    private String id;
    private String tableName;
    private List<String> columns;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getTableName() {
        return tableName;
    }

    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public List<String> getColumns() {
        return columns;
    }

    public void setColumns(List<String> columns) {
        this.columns = columns;
    }


    /**
     *将其转换成sql
     * @return
     */
    public String transformSql() {
        StringBuilder sql = new StringBuilder(" ");
        if (CollectionUtils.isNotEmpty(columns)) {
            sql.append("SELECT ");
            sql.append(StringUtils.join(columns, ","));
            sql.append(" FROM ");
        }
        sql.append(tableName);
        return sql.toString();
    }

    @Override
    public String toString() {
        return "OriginalTableVO{" +
                "id='" + id + '\'' +
                ", tableName='" + tableName + '\'' +
                ", columns=" + columns +
                '}';
    }

}
